<?php
namespace app\admin\controller;
use app\admin\validate\UserValidate;
use app\admin\model\AnswerModel;
use think\facade\Request;
/**
 * 问答控制器
 * Class Advert
 * @package app\admin\controller
 */
class Answer extends UserValidate{
    /**
     * 问答分类首页
     * @return \think\response\View
     */
    public function index(){
        $index = AnswerModel::index();
        $this->assign('index',$index);
        return view();
    }

    /**
     * 添加分类
     * @return \think\response\View
     */
    public function classification(){
        if (!empty(input('qc_isrecommand'))){
                $date = AnswerModel::cation(input());
                return $this->add($date);
        }
        return view();
    }

    /**
     * 修改 1
     * 删除  2
     * @return \think\response\View|void
     */
    public function advertup(){
        if (input('state') == 1){
            if (empty(input('qc_name'))){
                $check = AnswerModel::adverts(input('qc_id'));
                $this->assign([
                    'check'=>$check,
                    'qc_id'=>input('qc_id')
                ]);
                return view();
            }
            $up = AnswerModel::advert(input(),input('state'));
           return $this->add($up);
        }
        AnswerModel::advert(input('qc_id'),input('state'));
        $this->success('删除成功');
    }

    /**
     *问题
     */
    public function answer(){
        $answer = AnswerModel::inquiry();
        $this->assign('answer',$answer);
        return view();
    }

    /**
     * 问题修改
     * 删除
     * @return \think\response\View
     */
    public function questionDetails(){
        if (input('state') == 1){
            $check = AnswerModel::details(input('qq_id'),1);
            $this->assign('check',$check);
            return view();
        }
        AnswerModel::advert(input('qc_id'),2);
        $this->success('删除成功');
    }

    public function add($date){
        if ($date === true){
            $this->success('成功');
        }
        $this->error($date);
    }
}